package com.fourool.goodsmall.controller;

import com.fourool.goodsmall.common.Result;
import com.fourool.goodsmall.service.GCategoryService;
import com.fourool.goodsmall.service.GGoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/goods")
public class GoodsController {

    @Autowired
    private GCategoryService categoryService;

    @Autowired
    private GGoodsService goodsService;

    // 商品分类列表
    @GetMapping("/category/list")
    public Result getCategoryList() {
        return Result.success(categoryService.findAll());
    }

    // 商品列表
    @GetMapping("/list")
    public Result getGoodsList() {
        return Result.success(goodsService.findAll());
    }

    // 商品详情
    @GetMapping("/detail/{id}")
    public Result getGoodsDetail(@PathVariable Integer id) {
        return Result.success(goodsService.findById(id));
    }
}